/*
 * led.h
 *
 *  Created on: 03.11.2011
 *      Author: g.kruglov
 */

#ifndef LED_H_
#define LED_H_

#include <avr/io.h>
#include <delay_util.h>

#define LED_PORT        PORTC
#define LED_DDR         DDRC
#define LED1_P          (1<<PC5)
#define LED2_P          (1<<PC6)

class Led_t {
private:
    uint16_t Timer;
    bool IsOn;
public:
    void Init(void)   { LED_DDR |= LED1_P | LED2_P; }
    void Deinit(void) { Off(); }
    void Task(void)   { if(!IsOn) if(DelayElapsed(&Timer, 126)) On(); }
    void Blink(void)  { Off(); DelayReset(&Timer); }
    void On(void)     { LED_PORT |=  LED1_P; IsOn = true;  }
    void Off(void)    { LED_PORT &= ~LED1_P; IsOn = false; }
    void Toggle(void) { LED_PORT ^=  LED1_P; IsOn = !IsOn; }
};

extern Led_t Led;


#endif /* LED_H_ */
